import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
//import 'package:flutter_easyrefresh/easy_refresh.dart';

import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_plugin_demo/flutter_plugin_demo.dart';
import 'package:flutterappmydemo/basis/DouyinLike.dart';

import 'package:flutterappmydemo/basis/bottom_navigation_bar_demo.dart';
import 'package:flutterappmydemo/basis/sql_demo.dart';
import 'package:flutterappmydemo/wxread/tab_navigator.dart';
import 'package:provider/provider.dart';

import 'basis/FlexibleSpaceBarDemo.dart';
import 'basis/base_libraries_used.dart';
import 'basis/basis_example.dart';
import 'basis/bloc_demo_page.dart';
import 'basis/bottommenu_demo.dart';
import 'basis/camera_page.dart';
import 'basis/chip_demo.dart';
import 'basis/complex_layout_demo.dart';
import 'basis/login_example.dart';
import 'basis/plugin_page.dart';
import 'basis/provider_demo_page.dart';
import 'basis/routes_demo.dart';
import 'basis/slider_demo.dart';
import 'basis/sliding_delete_demo.dart';
import 'basis/tabbarsample.dart';
import 'basis/videoapp_demo.dart';
import 'generated/i18n.dart';
import 'list/gridview_example.dart';
import 'list/listview_example.dart';
import 'list/scrollview_example.dart';
import 'dart:io';
import 'dart:ui';

import 'package:get/get.dart';

//void main() => runApp(MyApp());
void main() async {
  runApp(MyApp());
  /* if (Platform.isAndroid) {
    // 以下两行 设置android状态栏为透明的沉浸。写在组件渲染之后，是为了在渲染后进行set赋值，覆盖状态栏，写在渲染之前MaterialApp组件会覆盖掉这个值。
    SystemUiOverlayStyle systemUiOverlayStyle = SystemUiOverlayStyle(
      statusBarColor: Colors.deepOrangeAccent,
      systemNavigationBarColor: Colors.deepOrangeAccent,
    );
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  }*/

  //该方法，能把状态栏和导航栏颜色同时改变,比上面的方法更简单一些
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light.copyWith(
    statusBarColor: Colors.transparent,
    // systemNavigationBarColor: Colors.deepOrangeAccent,
  ));
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (context) => Counter()),
      ],
      child: GetMaterialApp(
        title: 'Flutter MyDemo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: MainScreen(),
        debugShowCheckedModeBanner: false,
        debugShowMaterialGrid: false,
        localizationsDelegates: [
          S.delegate,
          GlobalCupertinoLocalizations.delegate,
          GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate
        ],
        supportedLocales: S.delegate.supportedLocales,
      ),
    );
  }
}

class MainScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final size = MediaQuery.of(context).size;
    final width = size.width;
    final height = size.height;
    print('_VideoAppState.initState width=$width  height=$height');

    //获取状态栏的高度
    var top2 = MediaQueryData.fromWindow(window).padding.top;
    print('MainScreen.build top2=$top2');

    //显示底部栏(隐藏顶部状态栏)
    //SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]);
    //显示顶部栏(隐藏底部栏)
    // SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.top]);
    //隐藏底部栏和顶部状态栏
    // SystemChrome.setEnabledSystemUIOverlays([]);

    return Scaffold(
      appBar: AppBar(
        title: Text('主界面'),
      ),
      body: ListView(
        reverse: false,
        children: <Widget>[
          Center(
            child: RaisedButton(
              child: Text('flutter插件的使用'),
              onPressed: () async {
                Navigator.push(
                    context,
                    new MaterialPageRoute(
                        builder: (context) => new PluginPage()));
              },
            ),
          ),

          ///
          Center(
            child: RaisedButton(
              child: Text('实例-仿微信读书app'),
              onPressed: () async {
                Navigator.push(
                    context,
                    new MaterialPageRoute(
                        builder: (context) => new TabNavigator()));
              },
            ),
          ),

          Center(
            child: RaisedButton(
              child: Text('基础'),
              onPressed: () async {
                final result = await Navigator.push(
                    context,
                    new MaterialPageRoute(
                        builder: (context) => new BasisExample('56')));

                print('从上一个界面返回的值是：$result');
              },
            ),
          ),
          Center(
            child: RaisedButton(
              child: Text('一些基本依赖库的使用'),
              onPressed: () {
                Navigator.push(
                    context,
                    new MaterialPageRoute(
                        builder: (context) => new BaseLibrariesUsed()));
              },
            ),
          ),
          Center(
            child: RaisedButton(
              child: Text('滚动布局'),
              onPressed: () {
                Navigator.push(
                    context,
                    new MaterialPageRoute(
                        builder: (context) => new ScrollViewExample()));
              },
            ),
          ),

          ///
          Center(
            child: RaisedButton(
              child: Text('底部弹框'),
              onPressed: () {
                Get.to(new BottomMenuDemo());

                /* Navigator.push(
                    context,
                    new MaterialPageRoute(
                        builder: (context) => new BottomMenuDemo()));*/
              },
            ),
          ),

          ///
          Center(
            child: RaisedButton(
              child: Text('列表布局listView'),
              onPressed: () {
                Navigator.push(
                    context,
                    new MaterialPageRoute(
                        builder: (context) => new ListViewExample()));
              },
            ),
          ),
          Center(
            child: RaisedButton(
              child: Text('列表布局GridView'),
              onPressed: () {
                Navigator.push(
                    context,
                    new MaterialPageRoute(
                        builder: (context) => new GridViewExample()));
              },
            ),
          ),
          Center(
            child: RaisedButton(
              child: Text('表单组件'),
              onPressed: () {
                Navigator.push(
                    context,
                    new MaterialPageRoute(
                        builder: (context) => new LoginExample()));
              },
            ),
          ),
          Center(
            child: RaisedButton(
              child: Text('页面跳转路由'),
              onPressed: () {
                Navigator.push(
                    context,
                    new MaterialPageRoute(
                        builder: (context) => new RoutesDemo()));
              },
            ),
          ),
          Center(
            child: RaisedButton(
              child: Text('底部导航条'),
              onPressed: () {
                Navigator.push(
                    context,
                    new MaterialPageRoute(
                        builder: (context) => new BottomNavigationBarDemo()));
              },
            ),
          ),
          Center(
            child: RaisedButton(
              child: Text('TabBar选项卡示例'),
              onPressed: () {
                Navigator.push(
                    context,
                    new MaterialPageRoute(
                        builder: (context) => new TabBarSample()));
              },
            ),
          ),
          Center(
            child: RaisedButton(
              child: Text('复杂一些的布局界面'),
              onPressed: () {
                Navigator.push(
                    context,
                    new MaterialPageRoute(
                        builder: (context) => new ComplexLayoutDemo()));
              },
            ),
          ),
          Center(
            child: RaisedButton(
              child: Text('滑动删除示例'),
              onPressed: () {
                Navigator.push(
                    context,
                    new MaterialPageRoute(
                        builder: (context) => new SlidingDeleteDemo()));
              },
            ),
          ),

          ///
          Center(
            child: RaisedButton(
              child: Text('Provider 的基本用法'),
              onPressed: () {
                Navigator.push(
                    context,
                    new MaterialPageRoute(
                        builder: (context) => new ProviderDemoPage()));
              },
            ),
          ),

          ///
          Center(
            child: RaisedButton(
              child: Text('BloC 的基本用法'),
              onPressed: () {
                Navigator.push(
                    context,
                    new MaterialPageRoute(
                        builder: (context) => new BlocDemoPage()));
              },
            ),
          ),

          ///
          Center(
            child: RaisedButton(
              child: Text('可折叠组件用法'),
              onPressed: () {
                Navigator.push(
                    context,
                    new MaterialPageRoute(
                        builder: (context) => new FlexibleSpaceBarDemo()));
              },
            ),
          ),

          ///
          Center(
            child: RaisedButton(
              child: Text('Slider组件用法'),
              onPressed: () {
                Navigator.push(
                    context,
                    new MaterialPageRoute(
                        builder: (context) => new SliderDemo()));
              },
            ),
          ),

          ///
          Center(
            child: RaisedButton(
              child: Text('sql的用法'),
              onPressed: () {
                Navigator.push(context,
                    new MaterialPageRoute(builder: (context) => new SQLDemo()));
              },
            ),
          ),

          ///
          Center(
            child: RaisedButton(
              child: Text('仿抖音点赞'),
              onPressed: () {
                Navigator.push(
                    context,
                    new MaterialPageRoute(
                        builder: (context) => new DouyinLike()));
              },
            ),
          ),

          ///
          Center(
            child: RaisedButton(
              child: Text('Chip(碎片，俗话：标签)'),
              onPressed: () {
                Navigator.push(
                    context,
                    new MaterialPageRoute(
                        builder: (context) => new ChipDemo()));
              },
            ),
          ),

          ///
          Center(
            child: Tooltip(
              message: "长按无效",
              child: RaisedButton(
                child: Text('视频播放'),
                onPressed: () {
                  Navigator.push(
                      context,
                      new MaterialPageRoute(
                          builder: (context) => new VideoApp()));
                },
              ),
            ),
          ),

          ///
          Center(
            child: Tooltip(
              message: "你好吗",
              child: ElevatedButton(
                child: Text("ElevatedButton"),
                onPressed: () {},
              ),
            ),
          ),

          ///
          /*Center(
            child: RaisedButton(
              child: Text('Camera 组件'),
              onPressed: () {
                Get.to(new CameraApp());
              },
            ),
          ),*/

          ///
        ],
      ),
    );
  }
}
